﻿package de.gameduell.framework.facebook.app.pyramide {
	import de.gameduell.framework.facebook.app.Controller;

	import de.gameduell.facebook.service.gen.CatalogItem;
	import de.gameduell.framework.debug.Debug;

	public class BrickCondition {
	
		private var _friendsNeeded:int;
		private var _coinsNeeded:int;
		private var _cashItem:String;
		private var _brickType:String;
		private var _condition:String;
		private var _price:String = "4";
		private var controller:Controller;

		public function BrickCondition(aConditionXML:XML) {
			controller = Controller.getInstance();
			_brickType = String(aConditionXML.@type);
			_friendsNeeded = int(aConditionXML.@friends);
			_coinsNeeded = int(aConditionXML.@coins);
			_cashItem = String(aConditionXML.@cash);
			
			switch(true){
				case _friendsNeeded > 0:
					_price = String(_friendsNeeded);
					_condition = "friends";
					break;
				case _coinsNeeded > 0:
					_price = String(_coinsNeeded);
					_condition = "coins";
					break;
				case cashNeeded:
					_condition = "cash";
					break;
				default:
					_price = "free";
					_condition = "none";
			}
		}
		
		public function get brickType():String {
			return _brickType;
		}
		
		public function get friendsNeeded():int {
			return _friendsNeeded;
		}
		
		public function get coinsNeeded():int {
			return _coinsNeeded;
		}
		
		public function get cashNeeded():Boolean {
			return _cashItem != "0";
		}

		public function get cashItem():String {
			return _cashItem;
		}
		
		public function get condition():String {
			return _condition;
		}
		
		public function get price():String {
			if(cashNeeded){
				var catItem:CatalogItem = controller.catalog.getItemByTitle(_cashItem);
				_price = String(catItem.price);
			}
			return _price;
		}
	}
}
